package com.swjd.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.swjd.po.User;
@Controller
public class UserController {
	@RequestMapping("/login")
	public String toLogin() {
		return "login";
	}

	@RequestMapping("/login2")
	public String toLogin2(User user, HttpSession session, Model model) {
		String username = user.getUsername();
		String password = user.getPassword();
		//模拟数据库，判断用户名密码是否相同
		if (username != null && username.equals("zhangsan") && password != null && password.equals("123456")) {
			//登陆成功后将用户名数据绑定到session中
			session.setAttribute("SESSION", user);
			return "redirect:main";
		} else {
			model.addAttribute("msg", "用户名或密码输入错误，请重新登陆！");
			return "login";
		}
	}

	@RequestMapping("/main")
	public String toMain() {
		return "main";
	}
	//用户退出后到此
	@RequestMapping("/deleteSession")
	public String deleteSession(HttpSession session) {
		//删除session信息
		session.invalidate();
		return "login";
	}

}
